package com.sikaryofficial.qrcode.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author : qinjinyuan
 * @desc : 积分规则枚举
 * @date : 2023/10/31 19:23
 */
@Getter
@AllArgsConstructor
public enum DownloadTaskStatusEnum {

    /**
     * 积分来源 1-扫码;
     */
    GENERATING(1, "生成中"),
    /**
     * 积分来源 2-签到；
     */
    DOWNLOADABLE(2, "可下载");
    private final Integer code;
    private final String desc;

    public static DownloadTaskStatusEnum getByCode(Integer code) {
        return Arrays.stream(DownloadTaskStatusEnum.values())
                .filter(downloadTaskStatusEnum -> Objects.nonNull(code) && code.equals(downloadTaskStatusEnum.getCode()))
                .findFirst().orElse(null);
    }

    public static String getDescByCode(Integer code) {
        DownloadTaskStatusEnum downloadTaskStatusEnum = getByCode(code);
        return Objects.isNull(downloadTaskStatusEnum) ? null : downloadTaskStatusEnum.getDesc();
    }

}
